//package com.example.controller;
//
//import com.example.config.FlinkConfig;
//import org.apache.flink.client.deployment.StandaloneClusterId;
//import org.apache.flink.client.program.rest.RestClusterClient;
//import org.apache.flink.configuration.Configuration;
//import org.apache.flink.configuration.RestOptions;
//import org.apache.flink.runtime.messages.webmonitor.ClusterOverview;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//@RestController
//@RequestMapping("/api/flink")
//public class FlinkConfigTestController {
//
//    @Autowired
//    private FlinkConfig flinkConfig;
//
//    @PostMapping("/test-connection")
//    public String testFlinkConnection() {
//        try {
//            Configuration configuration = new Configuration();
//            configuration.setString(RestOptions.ADDRESS, flinkConfig.getRemote().getHost());
//            configuration.setInteger(RestOptions.PORT, flinkConfig.getRemote().getPort());
//
//            try (RestClusterClient<StandaloneClusterId> client = new RestClusterClient<>(configuration, StandaloneClusterId.getInstance())) {
//                ClusterOverview overview = client.getClusterOverview().get();
//                StringBuilder sb = new StringBuilder();
//                sb.append("=== Flink 集群连接测试 ===\n");
//                sb.append("TaskManager 数量: ").append(overview.getNumTaskManagersConnected()).append("\n");
//                sb.append("总 Slot 数量: ").append(overview.getNumSlotsTotal()).append("\n");
//                sb.append("可用 Slot 数量: ").append(overview.getNumSlotsAvailable()).append("\n");
//                sb.append("运行中的作业数: ").append(overview.getNumJobsRunningOrPending()).append("\n");
//                sb.append("已完成作业数: ").append(overview.getNumJobsFinished()).append("\n");
//                sb.append("已取消作业数: ").append(overview.getNumJobsCancelled()).append("\n");
//                sb.append("已失败作业数: ").append(overview.getNumJobsFailed()).append("\n");
//                sb.append("=== 连接测试完成 ===");
//                return sb.toString();
//            }
//        } catch (Exception e) {
//            return "Flink 连接失败: " + e.getMessage();
//        }
//    }
//}